/*
 * @Description:
 * @Autor: GuluGuluu
 * @Date: 2023-06-27 23:33:03
 * @LastEditors: GuluGuluu
 * @LastEditTime: 2023-07-02 01:59:13
 */
import { useEffect } from "react";

export const useMount = (callback) => {
  useEffect(() => {
    callback();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
};

// base64 转file
export function base64toFile(dataUrl, fileName = "image") {
  let arr = dataUrl.split(",");
  let mime = arr[0].match(/:(.*?);/)[1];

  let bstr = window.atob(arr[1]); // base64编码
  let n = bstr.length;
  let u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n); // unicode 编码
  }
  return new File([u8arr], `${fileName}.png`, {
    type: mime,
  });
}
